import R from "@common/type/response";
import { NextApiResponse } from "next";
import * as roleService from '@/common/service/sys_role';
import { AuthenticatedRequest, withAuth } from '@common/middleware/auth';

export async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
    const query = req.query;
    const data = await roleService.getRoleOptions(query);
    if (data) {
        const options = data.map((item:any)=>({
            label: item.role_name,
            value: item.role_id
        }));
        R.success(res, options);
    } else {
        R.error(res, '获取角色列表失败');
    }
}

export default withAuth(handler);   